package com.tanjie.blackbean.pojo.response;

import lombok.Data;

/**
 * @author: tanjie
 * @date: 2022-03-30
 **/
@Data
public class ExtendResponse implements ResponseBean {

    String msg;

    Integer resCode;

    Object content;

    public ExtendResponse() {
    }

    public ExtendResponse(IResult result) {
        this.setResCode(result.getCode());
        this.setMsg(result.getMessage());
    }

    @Override
    public ResponseBean create(IResult result, Object data) {
        this.setResCode(result.getCode());
        this.setMsg(result.getMessage());
        this.setContent(data);
        return this;
    }

    @Override
    public ResponseBean success() {
        this.setResCode(defaultSuccessCode());
        this.setMsg(defaultSuccessMessage());
        return this;
    }

    @Override
    public ResponseBean successWithMessage(String message) {
        this.setResCode(defaultSuccessCode());
        this.setMsg(message);
        return this;
    }

    @Override
    public ResponseBean success(Object data) {
        this.setContent(data);
        this.setMsg(defaultSuccessMessage());
        this.setResCode(defaultSuccessCode());
        return this;
    }

    @Override
    public ResponseBean success(Object data, String message) {
        this.setContent(data);
        this.setMsg(message);
        this.setResCode(defaultSuccessCode());
        return this;
    }

    @Override
    public ResponseBean failure() {
        this.setMsg(defaultFailureMessage());
        this.setResCode(defaultFailureCode());
        return this;
    }

    @Override
    public ResponseBean failureWithMessage(String message) {
        this.setMsg(message);
        this.setResCode(defaultFailureCode());
        return this;
    }

    @Override
    public ResponseBean failure(Object data) {
        this.setContent(data);
        this.setMsg(defaultFailureMessage());
        this.setResCode(defaultFailureCode());
        return this;
    }

    @Override
    public ResponseBean failure(Object data, String message) {
        this.setContent(data);
        this.setMsg(message);
        this.setResCode(defaultFailureCode());
        return this;
    }

}
